<template>
  <el-card shadow="hover" style="margin: 18px 18px 0">
    <el-form inline>
      <el-form-item style="margin-right: 30px">
        <el-input placeholder="角色名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">查询</el-button>
        <el-button>清空</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary">添加</el-button>
    <el-button type="danger">批量删除</el-button>
    <el-table style="margin-top: 20px" stripe border :data="roledata">
      <el-table-column type="selection"></el-table-column>
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column label="角色名称" prop="roleName"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="{ row }">
          <el-button
            type="info"
            size="mini"
            icon="el-icon-info"
            title="分配权限"
            @click="
              $router.push(`/acl/role/auth/${row.id}?roleName=${row.roleName}`)
            "
          ></el-button>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            title="修改角色"
          ></el-button>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            title="删除角色"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :page-size="limit"
      :total="total"
      :current-page="page"
      :page-sizes="[5, 10, 15]"
      layout="prev,pager,next,jumper,->,sizes,total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </el-card>
</template>

<script>
import { requestRoleListByPage } from "@/api/role";

export default {
  name: "Role",
  data() {
    return {
      roledata: [],
      page: 1,
      limit: 5,
      total: 0,
    };
  },
  mounted() {
    this.getRoledataList();
  },
  methods: {
    async getRoledataList() {
      const { page, limit } = this;
      const res = await requestRoleListByPage(page, limit);
      console.log(res);
      this.roledata = res.data.items;
      this.total = res.data.total;
    },
    // 当前页改变
    handleCurrentChange(v) {
      this.page = v;
      this.getRoledataList();
    },
    // 每页显示条数改变
    handleSizeChange(v) {
      this.limit = v;
      this.getRoledataList();
    },
  },
};
</script>

<style scoped></style>
